#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>    
#include <fcntl.h>
#include <string.h>
#include <unistd.h>

int main()
{
	int fd = open("bite.txt",O_CREAT | O_TRUNC | O_RDWR,0664);
	if(fd == -1)
	{
		perror("open");
		exit(1);
	}
	const char* msg = "i like linux!\n";
	ssize_t w = write(fd,msg,strlen(msg));
	if(w == -1)
	{
		perror("wrrite");
		close(fd);
		exit(1);
	}
	off_t pos = lseek(fd, 0, SEEK_SET);
    if (pos == -1)
	{
        perror("lseek failed");
        close(fd);
        exit(1);
    }
	char str[1024];
	ssize_t r = read(fd,str,sizeof(str));
	if(r == -1)
	{
		perror("read");
		close(fd);
		exit(1);
	}
	printf("%s",str);
	close(fd);
	return 0;
}
